package practice;


import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

public class NewSearch {
	private WebDriver driver;
	private String baseUrl;
	private StringBuffer verificationErrors = new StringBuffer();
	@Before
	public void setUp() throws Exception {
		driver = new ChromeDriver();
		baseUrl = "http://www.google.com.au";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@Test
	public void testGoogleNexus4() throws Exception {
		driver.get(baseUrl + "/");
		//driver.findElement(By.id("gbqfq")).clear();
		driver.findElement(By.name("q")).clear();
		driver.findElement(By.name("q")).sendKeys("nexus 4");
		
		driver.findElement(By.id("gbqfb")).click();
		//driver.findElement(By.id("gbqfq")).sendKeys("nexus 4");
		//driver.findElement(By.name("btnK")).click();
		String TitleUrl = driver.getTitle();
		
		if(TitleUrl.equals("Google")){System.out.println("You are doing well");}
		else {System.out.println("Something wrong");}
		
	}

	@After
	public void tearDown() throws Exception {
		//driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}

